<?php if(count($ctx->getContatcts['result'])>0) { ?>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
 
 <tr>
    <td align="left"><a href="javascript:void(0);" class="l_gray_links1" onclick="CheckAll()">Check All</a> <span class="gray_txt_s">|</span> <a href="javascript:void(0);" class="l_gray_links1" onclick="ClearAll()">Uncheck All</a></td>
  </tr>
<tal:block tal:repeat="friends  getContatcts/result">
    <?php //print "<pre>";print_r($ctx->friends);
	//echo $ctx->friends['photo'];exit;
if( $ctx->friends['photo'] != '' && file_exists('../'.$ctx->userImage . $ctx->friends['photo']) ){
	//echo 'TRUE';exit;
$image = '/'.$ctx->userImage.$ctx->friends['photo']."?".time();
} else { 
	$image = "/images/ProfileDefUser.gif?".time();
}  
?>
    <tr>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="bot_border-3"><table width="100%" border="0" cellspacing="0" cellpadding="3">
                <tr>
                  <td width="4%" valign="top" align="center">
                  <input type="checkbox" name="chk" id="" value="<?php echo urlencode($ctx->friends['id']);?>" />
                  </td>
                  <td width="4%"><a href="/profile/index/profile/<?php echo base64_encode($ctx->friends['user_id']);?>"><img src="<?=$image;?>" class="img_border" alt="<?php echo $ctx->friends['first_name'];?>" title="<?php echo $ctx->friends['first_name'];?>" height="33" width="35" /></a></td>
                  <td width="88%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="68%"><a href="/profile/index/profile/<?php echo base64_encode($ctx->friends['user_id']);?>" class="blue_text_link_3"><?php echo $ctx->friends['first_name'];?></a></td>
                        <td width="32%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="8%"><!--<img src="/images/msg_icon.gif"  />--></td>
                              <td width="34%">
								&nbsp;
							  </td>
                              <td width="29%"><img src="/images/invite_icon.gif" style="padding-right:5px;" /><select id="group" name="group" class="medium txt_sm" onChange="addtogroup(this.value,'<?php echo urlencode($ctx->friends['contact_id']);?>')" style="width:90px;height:21px;">
								<option value="0">Add to group</option>
								<?php 
								$i=0;
								while($i<($ctx->count))
								{ ?>
								<?php $group_id= $ctx->group_details[$i]['group_id']; ?>
								<option value="<?php echo $group_id;?>"><?php echo $ctx->group_details[$i]['name']; ?></option>  
								<?php $i++; }?>
								</select></td>
                              <td width="29%"><a href="javascript:void(0);" class="l_gray_links1" onclick="deleteAll('One','<?php echo urlencode($ctx->friends['id']);?>');">Delete</a></td>
                            </tr>
                          </table></td>
                      </tr>

                    </table></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>

</tal:block>
</table>
<div id="topPagerId" class="paginat"></div>
<?php } else { ?>
<div style="padding:100px 50px"><b><center>No contatcts found</center></b></div>
<?php } ?>
<script type="text/javascript">
//<![CDATA[
function CheckAll() {
	
	var checks = document.getElementsByTagName('INPUT');
	var len = checks.length;
	for (var i = 0; i < len; i++) {
	   if (checks[i].name == 'chk') {
			checks[i].checked=true
	   }
	}
	
}
function ClearAll() {
	var checks = document.getElementsByTagName('INPUT');
	var len = checks.length;
	for (var i = 0; i < len; i++) {
	   if (checks[i].name == 'chk')  {
			checks[i].checked=false
	   }
	}
}

function deleteAll(callType,Value) {		
   var oneSelected =0,list="";
   var checks = document.getElementsByTagName('INPUT');
   var len = checks.length;
   for (var i = 0; i < len; i++) {
	   if (checks[i].name == 'chk'  ) {
			if(checks[i].checked) {
					list += checks[i].value + ",";
					oneSelected++;
			}
		}
	}
	//alert(list);
	if(callType == 'All') {
		if( oneSelected ==0 ) {  alert('Select at least one member.'); return false; };
	}
if(confirm('Aru you sure to delete ?')) {
if(callType == 'One' && Value!='')
{
		$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "/contacts/index/delete-contact/",
			   data: {list:Value},
			   success: function(data){
					ajaxPager(<?php echo $ctx->getContatcts['currentPage'];?>);
			   }
		});
}
	else 
	{
			$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "/contacts/index/delete-contact/",
			   data: {list:list},
			   success: function(data){
					ajaxPager(<?php echo $ctx->getContatcts['currentPage'];?>);
			   }
		});
	}
}
	
} 
function addtogroup(val,contactId) 
{ 
		//alert($("#group").val());
		//alert(val);return false;
		//var getVal = $("#group").val();
		//alert(getVal);return false;
	$.ajax({
			type: "POST",
			dataType: "json",
			data: "val="+val+"&userId="+contactId,
			//alert(a);return false;
			url: "/expressions/index/addtogroup/",
			success: function(data){
			//alert(data.output);return false;
					if(data.output==1)
					{
					alert('Contacts Added to group.');
					}
					else
					{
					alert('User already exist in this group.')
					}
					ajaxPager(<?php echo $ctx->getContatcts['currentPage'];?>);					
				}
		}); 
}

//]]>
</script>
